Java 7 Concurrency Cookbook by Unknown

Java 7 Concurrency Cookbook by Unknown

Author:Unknown
Language: eng
Format: epub
Publisher: Packt Publishing


There's more...

The CompletionService class can execute Callable or Runnable tasks. In this example, you have used Callable, but you could also send Runnable objects. Since Runnable objects don't produce a result, the philosophy of the CompletionService class doesn't apply in such cases.

This class also provides two other methods to obtain the Future objects of the finished tasks. These methods are as follows:

poll(): The version of the poll() method without arguments checks if there are any Future objects in the queue. If the queue is empty, it returns null immediately. Otherwise, it returns its first element and removes it from the queue.

take(): This method, without arguments, checks if there are any Future objects in the queue. If it is empty, it blocks the thread until the queue has an element. When the queue has elements, it returns and deletes its first element from the queue.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.